

  
import org.apache.log4j.Logger;
 
import com.herohead.CDLogger;
import com.herohead.Misc;
import com.herohead.Rabbitmq;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.GetResponse;
import com.rabbitmq.client.QueueingConsumer;

public class delSS {

// Replaced by nw   com.herohead.backup.DELSSID.java
	
	
	private static org.apache.log4j.Logger log= Logger.getLogger(delSS.class);
	static Channel ch;
	static Channel channel;
	
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		final CDLogger l = new CDLogger();
		
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() { 
				l.programStop(log);
			}
		});
		
		String username = args[0];
		String password = args[1];
		String rabbitserver = args[2];
		
		Misc m = new Misc();

		
		
		l.programStart(log);
		
		String queue = "delssid";


		Rabbitmq rmq = new Rabbitmq();
		rmq.setHostname(rabbitserver);
		rmq.setLogin("backup", "networker", "backup");

		rmq.setupChannel();
		rmq.setQueue(queue);

		rmq.declareQueDurable();
		channel = rmq.getChannel();

		
		
		long deliveryTag;

		boolean autoAck = false;
		//GetResponse response = channel.basicGet(RMQQueue, autoAck);
		GetResponse response = null;
		@SuppressWarnings("unused")
		AMQP.BasicProperties props;
		Boolean w = false;
		System.out.println("Waiting for message");
		while (true) {
			
			response = channel.basicGet(queue, autoAck);
			if (response != null) {
				w = true;
			props = response.getProps();
			
			String message = new String(response.getBody());
			String[] mess = message.split("\n");
			deliveryTag = response.getEnvelope().getDeliveryTag();
			log.info("Deleting the following ssid/cloneid " + mess[0] +  " from file " + mess[1]);
			Misc.callex("nsrmm -d -y -s ch00sm33 -S " + mess[0]);
			
			channel.basicAck(deliveryTag, false);
			} else {
				if (w) {
				System.out.println("Waiting for message");
				w = false;
				}
			}
		}	
	
		
/*		
		
		do {
			response = channel.basicGet(queue, autoAck);
			if (response == null) {
				break;
			} else {
				props = response.getProps();
			
				String message = new String(response.getBody());
				deliveryTag = response.getEnvelope().getDeliveryTag();
				Misc.callex("nsrmm -d -y -S " + message);
				log.info("Deleting the following ssid/cloneid " + message);

				channel.basicAck(deliveryTag, false);
			}
		} while (true);
*/
	
		

		

	}
}
